package net.mikoo.seals.utils;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.codec.binary.Base64;

public class Base64Util {

	// base64字符串转化成图片

	public static InputStream transform2Image(String imgStr) throws IOException { // 对字节数组字符串进行Base64解码并生成图片
		if (imgStr == null) {
			return null;
		}
		imgStr = imgStr.split(",")[1];
		Base64 base64 = new Base64();

		// Base64解码
		byte[] b = base64.decode(imgStr);
		// for (int i = 0; i < b.length; ++i) {
		// if (b[i] < 0) {// 调整异常数据
		// b[i] += 256;
		// }
		// }

		InputStream is = new ByteArrayInputStream(b);
		return is;

	}
}
